package handler

import (
	"net/http"

	"github.com/iriver/ai-offer/backend/internal/logic"
	"github.com/iriver/ai-offer/backend/internal/svc"
	"github.com/zeromicro/go-zero/rest/httpx"
)

func GetUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// 从URL路径中获取用户ID
		userId := r.PathValue("id")
		if userId == "" {
			http.Error(w, "缺少用户ID", http.StatusBadRequest)
			return
		}

		l := logic.NewGetUserLogic(r.Context(), svcCtx)
		resp, err := l.GetUser(userId)
		if err != nil {
			httpx.Error(w, err)
		} else {
			httpx.OkJson(w, resp)
		}
	}
}
